package com.pentajock.docdb.gui;


import java.awt.*;
import javax.swing.*;

import com.pentajock.docdb.*;
import com.pentajock.docdb.types.*;
import com.pentajock.docdb.database.*;
import com.pentajock.docdb.utils.*;


public class ListRenderer extends DefaultListCellRenderer {
	private String departmentName = null;
	
	public ListRenderer() {
	}
	
	public ListRenderer(String userName) {
		departmentName = DBController.getUserDepartment(userName);
	}
	
	public ListRenderer(User u) {
		departmentName = u.getDepartmentName();
	}
	
    @Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean hasFocus) {
		Component c = super.getListCellRendererComponent(list, value, index, isSelected, hasFocus);
		try {
			Utils.rendererHelper(this, value, departmentName, isSelected, list);
		}
		catch (Exception e) {
			Main.printStackTrace(e, "Error adding " + value.toString() + " to listing");
		}
		return c;
	}

	public void setUserName(String userName) {
		departmentName = DBController.getUserDepartment(userName);
	}
}
